import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JavaRegexEx {
    public static void main(String[] args) {
        String content = "<p>The <code>Pattern</code> is a compiled "
                + "representation of a regular expression.</p>";

        Pattern pattern = Pattern.compile("(</?[a-z]*>)");

        Matcher matcher = p.matcher(content);

        while (matcher.find()) {
            System.out.println(matcher.group(1));
        }
    }

    public static void main1(String[] args) {

        // 按指定模式在字符串查找
        String line = "cat cat cat cattie cat";
        String pattern = "\\bcat\\b";

        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);

        // 现在创建 matcher 对象
        Matcher m = r.matcher(line);
        int count = 0;
        while(m.find()) {
            //System.out.println(m.find());
            count++;
            System.out.println("Match number "+count);
            System.out.println("start(): "+m.start());
            System.out.println("end(): "+m.end());
        }
//        if (m.find( )) {
//            System.out.println("Found value: " + m.group(0) );
//            System.out.println("Found value: " + m.group(1) );
//            System.out.println("Found value: " + m.group(2) );
//            System.out.println("Found value: " + m.group(3) );
//        } else {
//            System.out.println("NO MATCH");
//        }
    }
}

